<template>
	<view class="wrap">
		<view class="top-box">
			<ul class="tabs-ul">
				<li class="tabs-ul-li" :class="{active:index==current}" v-for="(item, index) in tabs" :key="index"
					@click="changeNav(index)">{{ item }}</li>
			</ul>
		</view>
		<view class="set-list" v-if="current==0">
			<view class="set-list-line">
				<u--text align="left" text="头像"></u--text>
				<view class="right-box u-flex">
					<button class="avatar-wrapper" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
						<image class="head-img" :src="avatar"></image>
					</button>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="set-list-line">
				<u--text align="left" text="昵称"></u--text>
				<view class="right-box u-flex">
					<input placeholder="昵称" type="nickname" v-model="nickname" placeholder-class="placeholderClass" />
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="set-list-line" @click="show = true">
				<u--text align="left" text="年龄"></u--text>
				<view class="right-box u-flex">
					<text>{{height}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="set-list-line">
				<u--text align="left" text="性别"></u--text>
				<view class="right-box u-flex">
					<ul class="tabs-ul">
						<li class="tabs-ul-li" :class="{active:item.id==activeTab}" v-for="(item, index) in sexTabs"
							:key="index" @click="changeTab(item.id)">{{ item.title }}</li>
					</ul>
				</view>
			</view>
			<view class="set-list-line" @click="show = true">
				<u--text align="left" text="身高"></u--text>
				<view class="right-box u-flex">
					<text>{{height}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="set-list-line" @click="show = true">
				<u--text align="left" text="常住地"></u--text>
				<view class="right-box u-flex">
					<text>{{height}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view class="set-list-line" @click="show = true">
				<u--text align="left" text="户籍地"></u--text>
				<view class="right-box u-flex">
					<text>{{height}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</view>
		<view class="set-list" v-if="current==1">
			<u--textarea placeholder="请填写个性介绍,500字以内" height="100" style="margin-top: 20upx;"></u--textarea>
			<view class="tips">温馨提示:个性介绍是征婚的重要环节,详细介绍兴趣爱好，性格特征,工作情况及家庭情况,有助于提高成功率。</view>
		</view>
		<view class="set-list" v-if="current==2">
			<view class="set-list-line" @click="show = true">
				<u--text align="left" text="年龄范围"></u--text>
				<view class="right-box u-flex">
					<text>{{height}}</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<u--textarea placeholder="请填写择偶标准,500字以内" height="100" style="margin-top: 20upx;"></u--textarea>
			<view class="tips">提示:正确合理的择偶定位，是征婚成功的最大保障，尽量放宽择偶标准，婚姻最后都是拼的人品</view>
		</view>
		<view class="set-list" v-if="current==3" style="padding-top: 30upx;">
			<u-upload
					:previewFullImage="true"
					width="100"
					height="100"
					uploadIcon='plus'
					:fileList="fileList1"
					@afterRead="afterRead"
					@delete="deletePic"
					name="1"
					multiple
					:maxCount="9"
				></u-upload>
		</view>
		<u-picker :show="show" :columns="columns" @confirm="confirm"></u-picker>
		<view class="button">
			<block v-if="current!=3">
				<u-button size="nomal" color="#e16b8c" :text="'保存并下一步,修改'+tabs[current+1]" @tap="next()"></u-button>
			</block>
			<block v-if="current==3">
				<u-button size="nomal" color="#e16b8c" text="保存,完成修改" @tap="next()"></u-button>
			</block>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: "https://cdn.uviewui.com/uview/album/1.jpg",
				nickname: "",
				activeTab: 1, // 当前活跃的选项卡ID
				tabs: ["完善资料","个性介绍","择偶标准","上传图片"],
				sexTabs: [{
						id: '1',
						title: '男'
					},
					{
						id: '2',
						title: '女'
					},
				],
				show: false,
				columns: [
					['中国', '美国', '日本']
				],
				height:"",
				current:0,
				value: false,
				fileList1: [],
			}
		},
		methods: {
			onChooseAvatar(e) {
				this.avatar = e.detail.avatarUrl
				this.uploadFilePromise(e.detail.avatarUrl)
			},
			changeTab(id) {
				this.activeTab = id;
			},
			changeNav(index){
				this.current=index
			},
			change(e) {
				console.log('change', e);
			},
			// 回调参数为包含columnIndex、value、values
			confirm(e) {
				console.log('confirm', e)
				this.show = false
				this.height=e.value[0]
			},
			next(){
				if(this.current==3){
					return;
				}
				this.current++
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					setTimeout(() => {
						resolve( 'https://cdn.uviewui.com/uview/album/1.jpg' )
					}, 1000)
					/* let a = uni.uploadFile({
						url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					}); */
				})
			},
		}
	}
</script>

<style lang="less">
	.steps-box{
		background: #FFFFFF;
	}
	.wrap {
		display: flex;
		flex-direction: column;
		background: #f4f4f4;
	}
	.tips{
		font-size:24upx;
		margin: 30upx 0;
		line-height: 40upx;
	}
	button::after {
		border: none;
	}

	button {
		margin-left: 0;
		margin-right: 0;
		padding-left: 0;
		padding-right: 0;
		line-height: 1;
		color: #FFFFFF;
		font-size: 28rpx;
		background: none;
		width: 100%;
		border: none;
	}

	.set-list {
		display: flex;
		flex-direction: column;
		padding: 0 30upx;
		background: #fff;

		.set-list-line {
			display: flex;
			flex-direction: row;
			padding: 30upx 0;
			background: #fff;
			border-bottom: 1rpx solid #E1E5ED;

			.right-box {
				font-size: 28upx;
				input {
					font-size: 28upx;
					text-align: right;
				}
			}
		}
	}

	.tabs-ul {
		display: flex;
		flex-direction: row;
		list-style: none;
		height: 65rpx;
		line-height: 65rpx;
		text-align: center;
		margin: 0;
		padding: 0;

		.tabs-ul-li {
			width: 100upx;
			height: 40upx;
			line-height: 40upx;
			text-align: center;
			border-radius: 50upx;
			font-size: 28upx;
		}

		.active {
			background-color: #e16b8c;
			color: #fff;
		}
	}
	.top-box{
		background-color: #FFFFFF;
		padding: 30upx;
		padding-bottom: 0;
		.tabs-ul {
			display: flex;
			flex-direction: row;
			list-style: none;
			height: 65rpx;
			line-height: 65rpx;
			text-align: center;
			margin: 0;
			padding: 0;
			justify-content: center;
			border-bottom: 1rpx solid #eee;
			padding-bottom: 20upx;
		
			.tabs-ul-li {
				width: 200upx;
				height: 60upx;
				line-height: 60upx;
				text-align: center;
				border-radius: 10upx;
				font-size: 28upx;
				border-top-left-radius: 0;
			}
		
			.active {
				background-color: #e16b8c;
				color: #fff;
			}
		}
	}
	.avatar-wrapper {
		border: 1upx solid #eee;
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		margin: auto;
	}

	.head-img {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50%;
		overflow: hidden;
	}

	.button {
		background: #fff;
		padding: 80upx 40upx 0upx 40upx;
		position: fixed;
		bottom: 30upx;
		left: 0;
		right: 0;
	}
	.contacts-cont {
		padding: 0 30upx;
	
		.contacts-item {
			align-items: center;
			border-bottom: 1rpx solid #eee;
			padding: 30upx 0;
	
			.telnum {
				font-size: 28upx;
			}
	
			.change-btn {
				height: 50upx;
				line-height: 50upx;
				width: 100upx;
				text-align: center;
				background: #e16b8c;
				color: #fff;
				font-size: 28upx;
				border-radius: 10upx;
			}
	
			input {
				text-align: right;
				font-size: 28upx;
			}
	
			.save-btn{
				margin-top: 20upx;
			}
		}
	}
</style>